package com.jfreer.mybatis.expand.javamapper.elements;

import com.jfreer.mybatis.expand.IntrospectedTableMyBatis3Freework;
import org.mybatis.generator.api.dom.java.*;
import org.mybatis.generator.codegen.mybatis3.javamapper.elements.AbstractJavaMapperMethodGenerator;

import java.util.Set;
import java.util.TreeSet;

/**
 * User: landy
 * Date: 14-6-28
 * Time: 下午6:38
 */
public class InsertInBatchMethodGenerator extends AbstractJavaMapperMethodGenerator {
    @Override
    public void addInterfaceElements(Interface interfaze) {
        Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
        importedTypes.add(FullyQualifiedJavaType.getNewListInstance());
        Method method = new Method();


        method.setReturnType(FullyQualifiedJavaType.getIntInstance());
        method.setVisibility(JavaVisibility.PUBLIC);
        method.setName(((IntrospectedTableMyBatis3Freework) introspectedTable).getInsertInBatchStatementId());

        FullyQualifiedJavaType parameterType = FullyQualifiedJavaType
                .getNewListInstance();
        FullyQualifiedJavaType listType;
        listType = new FullyQualifiedJavaType(
                introspectedTable.getBaseRecordType());

        importedTypes.add(listType);
        parameterType.addTypeArgument(listType);

        method.addParameter(new Parameter(parameterType, "records")); //$NON-NLS-1$

        context.getCommentGenerator().addGeneralMethodComment(method,
                introspectedTable);


        interfaze.addImportedTypes(importedTypes);
        interfaze.addMethod(method);




    }
}
